﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ProjectStorageLib.Project
{
    public class ProjectsImporterManager : DatabaseEntities
    {

        public ProjectsImporterManager()
            : base()
        {

        }
        public List<ProjectManager> ProjectManagers = new List<ProjectManager>();

        public ProjectManager GetNewManager()
        {
            var proj = new ProjectStorageDB.Project();
            this.ent.Projects.AddObject(proj);
            ProjectManager m = new ProjectManager(this, proj);
            ProjectManagers.Add(m);
            return m;
        }

        public enum ValidationResult
        { 
            OK
            ,NameNotUnique
        }
        public ValidationResult Validate()
        {
            ValidationResult res = ValidationResult.OK;
            if (ProjectManagers.Any(m => m.ExistsProject(m.Name)))
            {
                res |= ValidationResult.NameNotUnique;
            }
            return res;
        }

        public void Save()
        {
            this.ent.SaveChanges();
        }

        protected override void Dispose(bool flag)
        {
        }
    }
}
